﻿//载入基础页面
{extend name="common/base" /}

//页面单独CSS
{block name="CustomCSS"}
<link rel="stylesheet" href="__STATIC__/vendors/css/datatables/datatables.min.css">
<link rel="stylesheet" href="__STATIC__/vendors/js/bootstrap-input/css/fileinput.min.css">

{/block}

//页面单独JS
{block name="CustomJS"}
<script src="__STATIC__/vendors/js/bootstrap-input/js/fileinput.min.js"></script>
<script src="__STATIC__/vendors/js/bootstrap-input/js/locales/zh.js"></script>
<script src="__STATIC__/vendors/js/datatables/datatables.min.js"></script>
<script src="__STATIC__/vendors/js/noty/noty.min.js"></script>
<script>

    (function ($) {
    'use strict';
    // ------------------------------------------------------- //
    // Auto Hide
    // ------------------------------------------------------ //    
        $(function () {
            //定义表格
            var table = $('#table').DataTable({
                language: {
                    "url": "__STATIC__/vendors/js/datatables/cn.json"
                },
                lengthMenu: [
                    [10, 15, 20, -1],
                    [10, 15, 20, "所有"]
                ],//分页数目
                stateSave: true, 
                columnDefs: [
                    { "orderable": false, "targets": [8,9]}//禁止排序
                ]
            });
        });

    })(jQuery);

        //提交交车链接
    function deliver(url,name,vin){
        var n = new Noty({
            type: "warning",
            text: '确认客户名称为：</br>'+name+' 的订单已经交车了吗？</br>车架号为：'+vin+'</br>请慎重操作！ ',
            progressBar : true, 
            animation: {
                open: "animated bounceInRight",
                close: "animated bounceOutRight"
            },
            buttons: [
                Noty.button('确定', 'btn btn-danger', function () {
                    $.post(url, function(data, status){
                        if (status == "success") {
                            if (data == "ok") {
                                //提交成功后调用
                                new Noty({
                                    type: "success",
                                    layout: "topRight",
                                    text: "客户名称为 " + name + "订单已经交车",
                                    progressBar: true,
                                    timeout: 2500,
                                    animation: {
                                        open: "animated bounceInRight",
                                        close: "animated bounceOutRight"
                                    },
                                    callbacks: {
                                        afterShow: function() {
                                            window.location.reload();
                                        },
                                    }
                                }).show();
                            }else{
                                //提交失败后调用
                                new Noty({
                                    type: "error",
                                    layout: "topRight",
                                    text: "交车提交失败",
                                    progressBar: true,
                                    timeout: 2500,
                                    animation: {
                                        open: "animated bounceInRight",
                                        close: "animated bounceOutRight"
                                    }
                                }).show();
                            }
                        }
                    });//确认后执行urlSubmit()完成实际执行
                    n.close();
                }, {id: 'button1', 'data-status': 'ok'}),

                Noty.button('取消', 'btn btn-shadow', function () {
                    n.close();
                })
            ]
        }).show();
    };

</script>
{/block}

//页面名称
{block name="PageName"}
待处理订单列表
{/block}

//自定义Modal
{block name="Modal"}
{/block}

//主页面
{block name="main"}
<div class="row">
    <div class="col-xl-12">
        <!-- Export -->
        <div class="widget has-shadow">
        	<div class="widget-header bordered d-flex no-actions align-items-center">
                <h2>待处理订单列表 <small>绿色为已配车订单</small></h2>
            </div>
            <div class="widget-body">
                <div class="table-responsive">
                    <table id="table" class="table mb-0">
                        <thead>
                            <tr>
                                <th>订单时间</th>
                                <th>顾问</th>
                                <th>名称</th>
                                <th>电话</th>
                                <th>车系</th>
                                <th>配置</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {volist name="data" id="list"}
                            <tr {if $list.distribution == 1}style="color:green;"{/if}>
                                <td>{$list.create_date|date="m月d日"|raw}</td>
                                <td>{$list.sales|raw}</td>
                                <td>{$list.name|raw}</td>
                                <td>{$list.phone|raw}</td>
                                <td>{$list.vehicle|raw}</td>
                                <td>{$list.config|raw}</td>
                                <td class="td-actions">
                                    <div class="btn-group" role="group">
                                        {if $list.distribution == 1}
                                        <button type="button" class="btn btn-primary btn-sm mr-1 mb-2" onClick="deliver('{:url('Order/deliver',['id' => $list.id])}','{$list.name}','{$list.vin}')">交车</button>
                                        {/if}
                                        <button type="button" class="btn btn-warning btn-sm mr-1 mb-2"  onclick="javascript:window.location.href='{:url('Order/edit',['id' => $list.id,'type' => 'perfect'])}'">完善信息</button>
                                    </div>
                                </td>
                            </tr>
                            {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <!-- End Export -->
    </div>
</div>

<!-- End Centered Modal -->
{/block}

